package com.desheng.bigdata.flink.batch.transformation

import com.desheng.bigdata.flink.stream.transformation.Score
import org.apache.flink.api.scala._

/**
  * flink对dataset和datastram的分组操作进行的严格的api分离
  * 在dataset中使用groupby
  * 在datastream中使用keyby
  */
object _01Transformation4GroupByOps {
    def main(args: Array[String]): Unit = {
        val env = ExecutionEnvironment.getExecutionEnvironment

        val scores = env.fromCollection(List(
            Score(2, "语文", 80),
            Score(3, "数学", 70.5),
            Score(1, "英语", 30.5),
            Score(4, "体育", 60),
            Score(105, "体育", 100),
            Score(105, "英语", 56)
        ))

        val grouped: GroupedDataSet[Score] = scores.groupBy("course")
        grouped.sum("score").print()
    }
}
